home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dirut / dirm13.zip / DIRM_LIB.ASM next >
Assembly Source File  |  1990-11-02  |  9KB  |  312 lines

  1. ;-----------------------------------------------------------------------;
  2. ; This file contains the support files for DIRM v1.3 (c) 1990           ;
  3. ; by Michael P. Rice.  These must be assembled and linked to the .OBJ   ;
  4. ; file produced by DIRM13.ASM.  Portions of this source code are the    ;
  5. ; copyrighted property of Michael P. Rice and are not public domain.    ;
  6. ; DIRM v1.3 cannot be used commerically without consent.                ;
  7. ;-----------------------------------------------------------------------;
  8. .model small
  9.  
  10. .data
  11.  
  12.     public    SCREEN_PTR
  13.     public    SCREEN_X, SCREEN_Y
  14. SCREEN_SEG    DW    0b800h        ;Segment of the screen buffer
  15. SCREEN_PTR    DW    0        ;Offset into screen memory of cursor
  16. SCREEN_X    DB    0        ;Position of the screen cursor
  17. SCREEN_Y    DB    0
  18.  
  19.  
  20. .code
  21.  
  22.     public send_crlf
  23. ;-----------------------------------------------------------------------;
  24. ; This is a C callable procedure that sends a CR and LF to the screen.    ;
  25. ; Uses: UPDATE_VIRTUAL_CURSOR                        ;
  26. ;-----------------------------------------------------------------------;
  27. send_crlf    PROC
  28.     push ax
  29.     push dx
  30.     mov ah,2
  31.     mov dl,13            ;13 is ASCII for CR
  32.     int 21h
  33.     mov dl,10            ;10 is ASCII for LF
  34.     int 21h
  35.     call update_virtual_cursor    ;Update position of virtual cursor
  36.     pop dx
  37.     pop ax
  38.     ret
  39. send_crlf    ENDP
  40.  
  41.     public goto_col
  42. ;-----------------------------------------------------------------------;
  43. ; This procedure moves the screen pointer to the specified position     ;
  44. ; in AL (As I recall).                                                  ;
  45. ;-----------------------------------------------------------------------;
  46. goto_col    PROC
  47.     push ax
  48.     push bx
  49.     
  50.     mov al,SCREEN_Y
  51.     mov bl,80
  52.     mul bl
  53.     add al,dl
  54.     adc ah,0
  55.     shl ax,1
  56.     mov SCREEN_PTR,ax
  57.     mov SCREEN_X,dl
  58.  
  59.     pop bx
  60.     pop ax
  61.     ret
  62. goto_col    ENDP
  63.     public write_char
  64. ;-----------------------------------------------------------------------;
  65. ; This procedure outputs a character to the screen by writing directly    ;
  66. ; into screen memory, so that characters such as the backspace are    ;
  67. ; treated as any other character and are displayed.            ;
  68. ;                                    ;
  69. ; This procedure must do a bit of work to update the cursor position.    ;
  70. ;                                    ;
  71. ; On Entry:    DL    Byte to print on screen.            ;
  72. ;                                    ;
  73. ; Uses:        CURSOR_RIGHT                        ;
  74. ; Reads:    SCREEN_SEG, SCREEN_PTR                    ;
  75. ;-----------------------------------------------------------------------;
  76. write_char proc
  77.     push ax            ;Save registers used in procedure
  78.     push bx
  79.     push dx
  80.     push es
  81.  
  82.     mov ax,SCREEN_SEG    ;Get segment for screen memory
  83.     mov es,ax        ;Point ES to screen memory
  84.     mov bx,SCREEN_PTR    ;Pointer to character in screen memory
  85.  
  86.     mov dh,7        ;Use the normal attribute
  87.         mov es:[bx],dx          ;Write the character/attribute to screen
  88.     call cursor_right    ;Now move to next cursor position
  89.  
  90.     pop es
  91.     pop dx            ;Restore registers to precall value
  92.     pop bx
  93.     pop ax
  94.     ret
  95. write_char endp
  96.  
  97.     public    write_string
  98. ;-----------------------------------------------------------------------;
  99. ; This procedure writes a string of characters to the screen. The    ;
  100. ; string must end with    DB     0                    ;
  101. ;                                    ;
  102. ; On entry:    DS:DX    Address of the string                ;
  103. ;                                    ;
  104. ; Uses:        WRITE_CHAR                        ;
  105. ;-----------------------------------------------------------------------;
  106. write_string    proc
  107.     push ax
  108.     push dx
  109.     push si
  110.     pushf                ;Save direction flag
  111.     cld                ;Set direction for increment (forward)
  112.     mov si,dx            ;Place address into SI for LODSB
  113. string_loop:
  114.     lodsb                ;Get a character into the AL register
  115.     or al,al            ;Have we found a zero yet?
  116.     jz end_of_string        ;Yes, we are done with string
  117.     mov dl,al            ;No, write character
  118.     call write_char    
  119.     jmp string_loop
  120. end_of_string:
  121.     popf                ;Restore direction flag
  122.     pop si
  123.     pop dx
  124.     pop ax
  125.     ret
  126. write_string    endp
  127.  
  128.  
  129. cr    equ    13        ;Carriage return
  130. lf    equ    10        ;Line feed
  131.  
  132.  
  133.     public cursor_right
  134. ;-----------------------------------------------------------------------;
  135. ; This procedure moves the cursor one position to the right or to the    ;
  136. ; next line if the cursor was at the end of a line.            ;
  137. ;                                    ;
  138. ; Uses:        SEND_CRLF                        ;
  139. ; Writes:    SCREEN_PTR, SCREEN_X, SCREEN_Y                ;
  140. ;-----------------------------------------------------------------------;
  141. cursor_right    proc
  142.     inc SCREEN_PTR            ;Move to next cursor position (word)
  143.     inc SCREEN_PTR
  144.     inc SCREEN_X            ;Move to next column
  145.     cmp SCREEN_X,79            ;Make sure column <= 79
  146.     jbe ok
  147.     call send_crlf            ;Go to next line
  148. ok:
  149.     ret
  150. cursor_right    endp
  151.  
  152.  
  153.     public write_decimal
  154. ;-----------------------------------------------------------------------;
  155. ; This procedure writes a 16-bit, unsigned number in decimal notation.    ;
  156. ;                                    ;
  157. ; On Entry:    DX    N : 16-bit, unsigned number.            ;
  158. ;                                    ;
  159. ; Uses:        WRITE_HEX_DIGIT                        ;
  160. ;-----------------------------------------------------------------------;
  161. write_decimal proc
  162.     push ax            ;Save registers used here
  163.     push cx
  164.     push dx    
  165.     push si
  166.     mov ax,dx    
  167.     mov si,10        ;Will divide by 10 using SI
  168.     xor cx,cx        ;count of digits placed on stack
  169. non_zero:
  170.     xor dx,dx        ;Set upper word of N to 0
  171.     div si            ;Calculate N/10 and (N mode 10)
  172.     push dx            ;Push one more digit onto stack
  173.     inc cx            ;One more digit added
  174.     or ax,ax        ;N = 0 yet?
  175.     jne non_zero        ;Nope, continue
  176. write_digit_loop:
  177.     pop dx            ;Get the digits in reverse order
  178.     call write_hex_digit    
  179.     loop write_digit_loop
  180. end_decimal:
  181.     pop si            ;Restore regsiters
  182.     pop dx
  183.     pop cx
  184.     pop ax
  185.     ret
  186. write_decimal    endp
  187.  
  188.     public write_hex_digit
  189. ;-----------------------------------------------------------------------;
  190. ; This procedure converts the lower 4 bits of DL to a hex digit and    ;
  191. ; writes it to the screen.                        ;
  192. ;                                     ;
  193. ; On Entry:    DL    Lower 4 bits contain number to be printed    ;
  194. ;            in hex.                        ;
  195. ;                                    ;
  196. ; Uses:        WRITE_CHAR                        ;
  197. ;-----------------------------------------------------------------------;
  198. write_hex_digit proc
  199.     push dx            ;Save registers used
  200.     cmp dl,10        ;Is this nibble <10?
  201.     jae hex_letter        ;No? Convert to a letter!
  202.     add dl,"0"        ;Yes? Convert to a digit!
  203.     jmp Short write_digit    ;Now write this character
  204. hex_letter:
  205.     add dl,"A"-10        ;Convert to hex letter
  206. write_digit:
  207.     call write_char        ;Display the letter on the screen
  208.     pop dx            ;Restore register
  209.     ret            
  210. write_hex_digit endp
  211.  
  212.     public     update_virtual_cursor
  213. ;-----------------------------------------------------------------------;
  214. ; this procedure updates the position of our virtual cursor to agree    ;
  215. ; with the position of the real cursor.                    ;
  216. ;-----------------------------------------------------------------------;
  217. update_virtual_cursor   proc
  218.     push ax
  219.     push bx
  220.     push cx
  221.     push dx
  222.     mov ah,3            ;Ask for cursor position
  223.     xor bh,bh            ;On page 0
  224.     int 10h                ;get cursor position into DH, DL
  225.         call goto_xy                    ;Move virtual cursor to this position
  226.     pop dx
  227.     pop cx
  228.     pop bx
  229.     pop ax
  230.     ret
  231. update_virtual_cursor    ENDP
  232.  
  233.     public    goto_xy
  234. ;-----------------------------------------------------------------------;
  235. ; This procedure move the cursor                    ;
  236. ;                                    ;
  237. ; On entry:    DH    Row (Y)                        ;
  238. ;        DL    Column (X)                    ;
  239. ;-----------------------------------------------------------------------;
  240. goto_xy    proc
  241.     push ax
  242.     push bx
  243.     mov bh,0            ;Display page 0
  244.     mov ah,2            ;Call for SET CURSOR POSITION
  245.     int 10h
  246.  
  247.     mov al,dh            ;Get the row number
  248.     mov bl,80            ;Multiply by 80 chars per line
  249.     mul bl                ;AX = row * 80
  250.     add al,dl            ;Add column
  251.     adc ah,0            ;AX = row * 80 + column
  252.     shl ax,1            ;Convert to a byte offset
  253.     mov SCREEN_PTR,ax        ;Save the cursor offset
  254.     mov SCREEN_X,dl            ;Save the cursor position
  255.     mov SCREEN_Y,dh
  256.  
  257.     pop bx
  258.     pop ax
  259.     ret
  260. goto_xy    ENDP
  261.  
  262.         public  init_write_char
  263. ;-----------------------------------------------------------------------;
  264. ; You need to call this procedure before you call WRITE_CHAR since    ;
  265. ; WRITE_CHAR uses information set by this procedure.            ;
  266. ;-----------------------------------------------------------------------;
  267. init_write_char         proc
  268.     push ax
  269.     push bx
  270.     mov bx,0b800h            ;Set for color graphics display
  271.     int 11h                ;Get equipment information
  272.     and al,30h            ;Keep just the video display type
  273.